Post

Replies

Boosts

Views

Activity

Reply to Swift UI on iOS 14 not assigning new object to @State property
I thought I had the same problem in Xcode 12.0.1, where I updated a @State property without anything happening. I then added some print-outs and found the problem to be even more bizarre than the UI not updating. I fetched data from an external api, decoded it and set the optional state to the result, but when I printed the non-nil state value in didSet, the value was printed as nil. So, the @State property value didn't even seem to get applied, even though I set it to a non-nil value. I then replaced @State with an @ObservableObject and got some interesting prints that @State didn't provide. It turned out that I wasn't performing the network completion on the main queue, which the observable object clearly printed out wasn't allowed. After adjusting the code so the completion was performed on the main queue, everything started working, but the @State didSet still printed nil.
Oct ’20